import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
import { adminRoutes } from './routes'
import FrameLayout from './layout'

export default class App extends Component {
  render() {
    return (
      <FrameLayout>
        <Switch>
          {/* 一级菜单路由 */}
          {
            adminRoutes.map(route => (
              <Route key={route.path} path={route.path} component={route.component} exact={route.meta.exact} >
              </Route>
            ))
          }
          {/* 二级菜单路由 */}
          {
            adminRoutes.map(route => (
              route.children ?
                route.children.map(item => (
                  <Route key={item.path} path={item.path} component={item.component}></Route>
                ))
                : ''
            ))
          }

          <Redirect from="/admin" to="/home" />
          <Redirect to="/404" />
        </Switch>
      </FrameLayout>
    )
  }
}
